import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { AdminModule } from './admin/admin.module';
import { SharedModule } from './shared/shared.module';
import { ApiModule } from './api/api.module';
import { AcceptLanguageResolver, I18nModule, QueryResolver } from 'nestjs-i18n';
import * as path from 'path';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import methodOverride from 'src/shared/middlewars/method-override';
// import { LoggerModule } from './logger/logger.,module';
// import { WinstonModule } from 'nest-winston';
// import * as winston from 'winston';

@Module({
  imports: [
    // WinstonModule.forRoot({
    //   transports: [
    //     new winston.transports.Console({
    //       format: winston.format.combine(
    //         winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
    //         winston.format.printf(({ level, message, timestamp }) => {
    //           return `[Nest] ${(process as any).id} - ${timestamp} [${level}]: ${message}`;
    //         }),
    //       ),
    //     }), //控制台输出
    //     new winston.transports.File({
    //       filename: 'error.log',
    //       level: 'error', //只记录错误日志
    //     }),
    //   ],
    // }),
    I18nModule.forRoot({
      fallbackLanguage: 'en',
      loaderOptions: {
        path: path.join(__dirname, '/i18n/'),
        watch: true,
      },
      resolvers: [
        new QueryResolver(['lang', 'l']), //url传递查询 字符串 /app?lang=zh /app?l=zh
        AcceptLanguageResolver, //headers:{"Accept-Language":"zh,zh-CN;q=0.9,en;q=0.8"}
      ],
    }),
    AdminModule,
    SharedModule,
    ApiModule,
    // LoggerModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(methodOverride).forRoutes('*');
  }
  
}
